package heima.lm.oschina.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import heima.lm.oschina.BaseApplication;
import heima.lm.oschina.R;
import heima.lm.oschina.bean.Active;
import heima.lm.oschina.bean.Friend;
import heima.lm.oschina.utils.UIUtils;

/**
 * Created by Administrator on 2017/4/5.
 */

public class FriendCircleAdapter extends BaseRecyclerViewAdapter {

    public FriendCircleAdapter(List list) {
        super(list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(BaseApplication.mApp).inflate(R.layout.item_friend_circle,parent,false);
        return new FriendCircleViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        FriendCircleViewHolder viewHolder = (FriendCircleViewHolder) holder;
        Active active = (Active) mList.get(position);
        //设置item的值
        Glide.with(UIUtils.getContext()).load(active.getPortrait()).fitCenter().into(viewHolder.imgPortrait);//加载图片
        viewHolder.tvAuthor.setText(active.getAuthor());
        viewHolder.tvData.setText(active.getPubDate());
        viewHolder.tvTitile.setText(active.getObjectTitle());
        Spanned spanned = Html.fromHtml(active.getMessage());
        viewHolder.tvMessage.setText(spanned);
//        viewHolder.tvCommentCount.setText(active.getCommentCount());
    }

    //自定义的ViewHolder
    class FriendCircleViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.cimg_firend_cricle_portrait)
        ImageView imgPortrait;
        @BindView(R.id.tv_friend_circle_author)
        TextView tvAuthor;
        @BindView(R.id.tv_friend_circle_pubData)
        TextView tvData;
        @BindView(R.id.tv_friend_circle_objecttitle)
        TextView tvTitile;
        @BindView(R.id.tv_friend_circle_message)
        TextView tvMessage;
        @BindView(R.id.iv_friend_phone)
        ImageView imgPhone;
        @BindView(R.id.tv_friend_phone)
        TextView tvPhoneSystem;
        @BindView(R.id.tv_friend_circle_commentCount)
        TextView tvCommentCount;
        public FriendCircleViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
